Tab = {
	expanded:{},
	list:"overview,share,payments,reports,transaction",
	changing:false,
	current:"overview",
	animating:[], // jQuery object for animating element
	change:function(fundID,tab){
		if(Tab.list.indexOf(tab) > -1 && tab != Tab['_'+fundID].current){
			Tab['_'+fundID].current = tab;
			var $fund = $('#fund_'+fundID);
			var $selectedTab = $fund.find('.fund_tab.selected');
			var $tab = $('#'+fundID+'_'+tab);
			var $selectedArea = $fund.find('tr.current');
			var $tabArea = $fund.find('tr.'+tab);
			
			if(!$selectedTab.hasClass(tab)){
				$selectedTab.removeClass('selected');
				$tab.addClass('selected');

				if(tab != 'overview'){
					Tab.expand(fundID);
				} else {
					Tab.collapse(fundID);
				}
				
				$selectedArea.hide();
				$selectedArea.removeClass('current');
				$tabArea.addClass('current');
				
				// abort any in progress fades
				if(Tab.animating.length == 1){
					try{
						Tab.animating.stop(false,true);
						Tab.animating.hide();
					}catch(e){
						/*do nothing*/
					}
				}
				Tab.animating = $tabArea;
				$tabArea.fadeIn(function(){
					Tab.animating = [];
				});
				
				if(tab != 'overview'){
					Tab['load'+tab](fundID);
				}
			}
		}
	},
	expand:function(fundID,type,height){
		height = 260;
		if(!(fundID in Tab.expanded)){
			Fund.isExpanding = true;
			//Fund.expandedFund = fundID;
			Tab.expanded[fundID] = 1;
			var $fund = $('#fund_'+fundID);
			var $fundBottom = $fund.find('.fund-bottom');
			var $fundTable = $fund.find('table.fund-contents'); 
			var $fundProgress = $fund.find('.fund-progress-bar');
			$fundProgress.animate({height:(height+26)+'px'},300);
			$fundTable.animate({height:height+'px'},300,function(){
				Fund.isExpanding = false;
			});
			$fundBottom.fadeOut(300);
		}
	},
	collapse:function(fundID){
		var $fund = $('#fund_'+fundID);
		var $fundTable = $fund.find('table.fund-contents'); 
		var $fundProgress = $fund.find('.fund-progress-bar');
		var $fundBottom = $fund.find('.fund-bottom');
		
		$fundProgress.animate({height:'136px'},300);
		$fundTable.animate({height:'111px'},300,function(){
			//Fund.expandedFund = "";
			delete Tab.expanded[fundID];
		});
		$fundBottom.fadeIn(300);

	},
	loadshare:function(fundID){
		var $fund = $('#fund_'+fundID);
		var $shareRow = $fund.find('tr.share');
		var $share = $shareRow.children();
		
		if ($share.html().length < 200){
			$share.html(Fundr.getLoadingIcon('margin-left:274px;margin-top:91px;','tabLoading'));

			Ajax.run("fundView.renderShare",
				function(data){
					$share.html(data);
					Mailing.init(fundID);
				},
				{fundID:fundID}
			);
		}
	}
};